/************************************************************************
Purpose: 	Generate a data set of the statistics of period prices
*************************************************************************/

set more off
clear all
pause on

use "$TRADING_DATA_CLEAN/panel_plant-period-date-bid.dta", replace

*** Currently we are computing the simple average of bid prices over all bids.
*** Not sure if it makes more sense to compute average weighted by bid quantity.

bysort period: egen price_clearing_mean = mean(trade_price)
bysort period: egen price_clearing_median = median(trade_price)
bysort period: egen price_bid_mean = mean(bid_price)
bysort period: egen price_bid_median = median(bid_price)
keep period price_clearing_mean price_clearing_median price_bid_mean price_bid_median compliance_month_cap
rename compliance_month_cap period_cap
rename period id_period
duplicates drop
drop if id_period == .
save "$MODEL_DATA_OUT/period_statistics.dta", replace
export delimited using "$MODEL_DATA_OUT/period_statistics.txt", nolabel delimiter(tab) replace
